package IC.lir;

import java.util.HashMap;

import IC.AST.*;

public class ClassCreatorVisitor extends IC.AST.Visitor {
	
	private HashMap<String, ClassStructure> _classes = new HashMap<String, ClassStructure>(); 
	
	public Object Visit(Program root)
	{
		//We will parse them in hierarchical order because they must be defined in the file that way.
		for (ClassDeclaration decl : root.GetListOfClasses())
			decl.Visit(this);
		return _classes;
	}
	
	public Object Visit(ClassDeclaration decl)
	{
		if (decl.GetSuperClassID() == null)
				_classes.put(decl.GetID(), 
						new ClassStructure(
								decl.GetID(), decl.GetFields(), decl.GetMethods()));
		else
				_classes.put(decl.GetID(), 
						new ClassStructure(
								decl.GetID(), _classes.get(decl.GetSuperClassID()), decl.GetFields(), decl.GetMethods()));
		
		return null;
	}
}
